// ignore_for_file: constant_identifier_names

import 'dart:io';

import 'package:flutter/material.dart';

class MyAvatarImage extends StatelessWidget {
  final double? width;
  final double? height;
  final double radius;
  final fit;
  String url;
  Shape shape;

  MyAvatarImage(
    this.shape,
    this.url, {
    super.key,
    this.width,
    this.height,
    required this.radius,
    this.fit = BoxFit.cover,
  });

  @override
  Widget build(BuildContext context) {
    // ignore: unnecessary_null_comparison
    double? tRadius = radius != null ? 2 * radius + 4 : null;
    var img;
    switch (shape) {
      case Shape.NORMAL:
      case Shape.CIRCLE:
        if (url.contains('asset')) {
          img = AssetImage(url);
        } else {
          img = FileImage(File(url));
        }
        return Container(
          width: tRadius,
          height: tRadius,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(60),
              border: Border.all(width: 2, color: Colors.white),
              image: DecorationImage(image: img, fit: fit)),
        );
    }
  }
}

enum Shape {
  NORMAL,
  CIRCLE;
}
